#pragma once
#include "tab0.h"
#include "tab2.h"


/* BF81 is, with BF16 a key bit field in that program.
   The 81 bits of the field relate to the 81 cells of the grid.
   Again, that field can have may uses as, but not limited to

   cells controlled by one cell (not the same digit in these cells)
   description of a cell pattern
   unassigned cells
   rookeries (all candidates of the same digit)  
   BF81 is in fact a 128 bits fiels and could be used as such.
*/

//class B3_81:public BF3 {
//public:

//};


class PM3BF {
	// 9*BF81 to have candidates in native mode when needed
public:
	BF3 bfc[9];
	void SetAll_0();
	inline void Set(int dig,int cell){bfc[dig].Set(cell);}
	inline void SetU(UCAND c){bfc[c>>7].Set(c & 127);}
	void Set(BF9 & digs,int cell);
	void SetRegion (int dig,int unit,BF9 & pdigs);
	inline void Clear(int dig,int cell){bfc[dig].Clear(cell);}
	inline int SetIf(int dig,int cell){
			if(bfc[dig].On(cell)) return 0;
			bfc[dig].Set(cell);
			return 1;
		}	
	int operator ==( PM3BF & b) ;
	void operator &= ( PM3BF &z2);
	void operator |= ( PM3BF &z2);
	void operator -= ( PM3BF &z2);
	void operator &= ( BF3 * bf3);
	void Image(BUILDSTRING & zs);
	inline int On(int dig,int cell){return bfc[dig].On(cell);}
	inline int OnU(UCAND x){return bfc[x>>7].On(x & 0x7f);}
	inline int OffU(UCAND x){return bfc[x>>7].Off(x & 0x7f);}
	int IsEmpty(){for(int i=0;i<9;i++)
				if(bfc[i].IsNotEmpty()) return 0;
				return 1;}
	int Count();
};

class PM3BFONOFF{// small class managing both status
public:
	PM3BF bfon, bfoff;
	void SetAll_0(){bfon.SetAll_0(); bfoff=bfon;}
	inline void Set(SCAND x){
		PM3BF & mybf=(x & (1<<11))?bfoff:bfon;
		mybf.Set((x>>7) & 15, x & 0x7f);
	}
	inline int On(SCAND x){
		PM3BF & mybf=(x & (1<<11))?bfoff:bfon;
		return mybf.On((x>>7) & 15, x &0x7f);
	}
	USHORT Stringbits(UCAND * t);
	USHORT String(UCAND * t);

};





